import axios from 'axios';

// 创建单例
const instance = axios.create({
    baseURL: 'https://www.ahsj.link/nebula-api',
    timeout: 5000,
});

// 请求拦截
instance.interceptors.request.use(
    (config) => {
        let token = localStorage.getItem('token');
        if (token) {
            config.headers['x-auth-token'] = token;
        }
        return config;
    },
    (err) => {
        return Promise.reject(err);
    }
);

// 响应拦截
instance.interceptors.response.use(
    (res) => {
        return res.data;
    },
    (err) => {
        return Promise.reject(err);
    }
);

export default instance;
